﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Tauren.Business.Entity.Input;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Service.AccountInfo;

namespace Tauren.Business.Core.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [Route("api/account")]
    [ApiController]
    public class AccountInfoController : ControllerBase
    {
        private IAccountInfoService service { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_service"></param>
        public AccountInfoController(IAccountInfoService _service)
        {
            service = _service;
        }
        /// <summary>
        /// 新增账号信息
        /// </summary>
        /// <param name="input">账号信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/add")]
        public IActionResult Add([FromBody] Entity.Input.AccoutInfo_Input input) => service.Add(input).ToJsonResult();


        /// <summary>
        /// 编辑账号信息
        /// </summary>
        /// <param name="input">账号信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/editor")]
        public IActionResult Editor([FromBody] Entity.Input.AccoutInfo_Input input) => service.Editor(input).ToJsonResult();

        /// <summary>
        /// 获取单个账号信息数据
        /// </summary>
        /// <param name="id">账号实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/get/{id}")]
        public IActionResult Get([FromRoute] int id) => service.FirstOrDefault(id).ToJsonResult();

        /// <summary>
        /// 删除账号信息
        /// </summary>
        /// <param name="id">账号实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/del/{id}")]
        public IActionResult Delete([FromRoute] int id) => service.Delete(id).ToJsonResult();


        /// <summary>
        /// 账号信息
        /// </summary> 
        /// <param name="account">账号</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/acc/{account}")]
        public IActionResult GetByCode([FromRoute] string account) => service.GetByAccount(account).ToJsonResult();
         
         

        /// <summary>
        /// 获取所有数据
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/all")]
        public IActionResult All() => service.All().ToJsonResult();

        /// <summary>
        /// 分页获取 账号信息列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/pages")]
        public IActionResult Pages([FromBody] Entity.Global.QueryModel queryModel) => service.Pages(queryModel).ToJsonResult();


        /// <summary>
        /// 启用??
        /// </summary>
        /// <param name="id">账号ID</param> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/enable/{id:int}")]
        public IActionResult Enable(int id) => service.Enable(id).ToJsonResult();

        /// <summary>
        /// 根据组织获取 账号信息
        /// </summary>
        /// <param name="orgId">组织ID</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/orgs/{orgId}")]
        public IActionResult GetByOrgs([FromRoute] string orgId) => service.GetByOrgs(orgId).ToJsonResult();

        /// <summary>
        /// 注册账号
        /// </summary>
        /// <param name="Accounts">账户信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/register")]
        public IActionResult Register([FromBody]List<PersonInfo_InPut> Accounts) => service.Register(Accounts).ToJsonResult();

        /// <summary>
        /// 根据组织获取 账号信息
        /// </summary>
        /// <param name="accountId">账户ID</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/rest/{accountId}")]
        public IActionResult RestPassword([FromRoute]int accountId) => service.RestPassword(accountId).ToJsonResult();
    }
}
